package catchProcess;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

/**
 * @author Administrator
 * 监测数据库进程是否启动
 */
public class CatchProcess {
    public boolean catchCassandraPro() throws IOException, InterruptedException {

        Process process;
        //检测iotdb是否启动
        String[] cmds = {"/bin/sh", "-c", "ps -ef | grep /cassandra/"};

        //在本主机上执行该命令
        process = Runtime.getRuntime().exec(cmds);

        //进程等待
        process.waitFor();

        InputStream in = process.getInputStream();

        //读取流中的信息
        BufferedReader read = new BufferedReader(new InputStreamReader(in));

        //如果流中有信息则返回true
        //如果没有信息则返回false
        if(read.readLine() != null) {
            read.close();
            return true;
        }else {
            return  false;
        }

    }
}
